package com.wx.frame.serviceimpl;

import com.wx.frame.mapper.RolesMapper;
import com.wx.frame.service.RolesService;
import com.wx.utils.Page;
import com.wx.utils.Pageable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by myd on 15/12/25.
 */
@Service("rolesServiceImpl")
public class RolesServiceImpl<Roles> implements RolesService<Roles> {

    @Autowired
    public RolesMapper<Roles> rolesMapper;


    /**
     * 获取所有的数据
     * @param roles
     * @return
     */
    @Override
    public List<Roles> getAll(Roles roles)
    {
        return this.rolesMapper.getall(roles);
    }

    /**
     * 保存权限信息
     */
    @Override
    public int save(Roles roles)
    {
        return this.rolesMapper.save(roles);
    }

    /**
     * 删除权限信息，支持批量删除
     * @param idList
     */
    @Override
    public int delete(List<String> idList) {
        return this.rolesMapper.delete(idList);
    }

    /**
     *分页获取权限信息
     * @param pageable
     * @param roles
     * @return
     */
    @Override
    public Page<Roles> findPage(Pageable pageable,Roles roles)
    {
        Map<String,Object> map=new HashMap();
        map.put("pageable",pageable);
        map.put("roles",roles);
        List<Roles> list=this.getAll(roles);
        List<Roles> roless=this.rolesMapper.findpage(map);
        Page<Roles> page=new Page<>();
        page.setRows(roless);
        page.setTotalCount(roless.size());
        page.setPage(pageable.getPage());
        page.setTotal(list.size());
        return page;
    }

}
